// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Fluent;
using Elastic.Clients.Elasticsearch.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Rollup;

public sealed partial class Groupings
{
	/// <summary>
	/// <para>
	/// A date histogram group aggregates a date field into time-based buckets.
	/// This group is mandatory; you currently cannot roll up documents without a timestamp and a <c>date_histogram</c> group.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("date_histogram")]
	public Elastic.Clients.Elasticsearch.Rollup.DateHistogramGrouping? DateHistogram { get; set; }

	/// <summary>
	/// <para>
	/// The histogram group aggregates one or more numeric fields into numeric histogram intervals.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("histogram")]
	public Elastic.Clients.Elasticsearch.Rollup.HistogramGrouping? Histogram { get; set; }

	/// <summary>
	/// <para>
	/// The terms group can be used on keyword or numeric fields to allow bucketing via the terms aggregation at a later point.
	/// The indexer enumerates and stores all values of a field for each time-period.
	/// This can be potentially costly for high-cardinality groups such as IP addresses, especially if the time-bucket is particularly sparse.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("terms")]
	public Elastic.Clients.Elasticsearch.Rollup.TermsGrouping? Terms { get; set; }
}

public sealed partial class GroupingsDescriptor<TDocument> : SerializableDescriptor<GroupingsDescriptor<TDocument>>
{
	internal GroupingsDescriptor(Action<GroupingsDescriptor<TDocument>> configure) => configure.Invoke(this);

	public GroupingsDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Rollup.DateHistogramGrouping? DateHistogramValue { get; set; }
	private Elastic.Clients.Elasticsearch.Rollup.DateHistogramGroupingDescriptor<TDocument> DateHistogramDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Rollup.DateHistogramGroupingDescriptor<TDocument>> DateHistogramDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Rollup.HistogramGrouping? HistogramValue { get; set; }
	private Elastic.Clients.Elasticsearch.Rollup.HistogramGroupingDescriptor<TDocument> HistogramDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Rollup.HistogramGroupingDescriptor<TDocument>> HistogramDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Rollup.TermsGrouping? TermsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Rollup.TermsGroupingDescriptor<TDocument> TermsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Rollup.TermsGroupingDescriptor<TDocument>> TermsDescriptorAction { get; set; }

	/// <summary>
	/// <para>
	/// A date histogram group aggregates a date field into time-based buckets.
	/// This group is mandatory; you currently cannot roll up documents without a timestamp and a <c>date_histogram</c> group.
	/// </para>
	/// </summary>
	public GroupingsDescriptor<TDocument> DateHistogram(Elastic.Clients.Elasticsearch.Rollup.DateHistogramGrouping? dateHistogram)
	{
		DateHistogramDescriptor = null;
		DateHistogramDescriptorAction = null;
		DateHistogramValue = dateHistogram;
		return Self;
	}

	public GroupingsDescriptor<TDocument> DateHistogram(Elastic.Clients.Elasticsearch.Rollup.DateHistogramGroupingDescriptor<TDocument> descriptor)
	{
		DateHistogramValue = null;
		DateHistogramDescriptorAction = null;
		DateHistogramDescriptor = descriptor;
		return Self;
	}

	public GroupingsDescriptor<TDocument> DateHistogram(Action<Elastic.Clients.Elasticsearch.Rollup.DateHistogramGroupingDescriptor<TDocument>> configure)
	{
		DateHistogramValue = null;
		DateHistogramDescriptor = null;
		DateHistogramDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The histogram group aggregates one or more numeric fields into numeric histogram intervals.
	/// </para>
	/// </summary>
	public GroupingsDescriptor<TDocument> Histogram(Elastic.Clients.Elasticsearch.Rollup.HistogramGrouping? histogram)
	{
		HistogramDescriptor = null;
		HistogramDescriptorAction = null;
		HistogramValue = histogram;
		return Self;
	}

	public GroupingsDescriptor<TDocument> Histogram(Elastic.Clients.Elasticsearch.Rollup.HistogramGroupingDescriptor<TDocument> descriptor)
	{
		HistogramValue = null;
		HistogramDescriptorAction = null;
		HistogramDescriptor = descriptor;
		return Self;
	}

	public GroupingsDescriptor<TDocument> Histogram(Action<Elastic.Clients.Elasticsearch.Rollup.HistogramGroupingDescriptor<TDocument>> configure)
	{
		HistogramValue = null;
		HistogramDescriptor = null;
		HistogramDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The terms group can be used on keyword or numeric fields to allow bucketing via the terms aggregation at a later point.
	/// The indexer enumerates and stores all values of a field for each time-period.
	/// This can be potentially costly for high-cardinality groups such as IP addresses, especially if the time-bucket is particularly sparse.
	/// </para>
	/// </summary>
	public GroupingsDescriptor<TDocument> Terms(Elastic.Clients.Elasticsearch.Rollup.TermsGrouping? terms)
	{
		TermsDescriptor = null;
		TermsDescriptorAction = null;
		TermsValue = terms;
		return Self;
	}

	public GroupingsDescriptor<TDocument> Terms(Elastic.Clients.Elasticsearch.Rollup.TermsGroupingDescriptor<TDocument> descriptor)
	{
		TermsValue = null;
		TermsDescriptorAction = null;
		TermsDescriptor = descriptor;
		return Self;
	}

	public GroupingsDescriptor<TDocument> Terms(Action<Elastic.Clients.Elasticsearch.Rollup.TermsGroupingDescriptor<TDocument>> configure)
	{
		TermsValue = null;
		TermsDescriptor = null;
		TermsDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (DateHistogramDescriptor is not null)
		{
			writer.WritePropertyName("date_histogram");
			JsonSerializer.Serialize(writer, DateHistogramDescriptor, options);
		}
		else if (DateHistogramDescriptorAction is not null)
		{
			writer.WritePropertyName("date_histogram");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Rollup.DateHistogramGroupingDescriptor<TDocument>(DateHistogramDescriptorAction), options);
		}
		else if (DateHistogramValue is not null)
		{
			writer.WritePropertyName("date_histogram");
			JsonSerializer.Serialize(writer, DateHistogramValue, options);
		}

		if (HistogramDescriptor is not null)
		{
			writer.WritePropertyName("histogram");
			JsonSerializer.Serialize(writer, HistogramDescriptor, options);
		}
		else if (HistogramDescriptorAction is not null)
		{
			writer.WritePropertyName("histogram");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Rollup.HistogramGroupingDescriptor<TDocument>(HistogramDescriptorAction), options);
		}
		else if (HistogramValue is not null)
		{
			writer.WritePropertyName("histogram");
			JsonSerializer.Serialize(writer, HistogramValue, options);
		}

		if (TermsDescriptor is not null)
		{
			writer.WritePropertyName("terms");
			JsonSerializer.Serialize(writer, TermsDescriptor, options);
		}
		else if (TermsDescriptorAction is not null)
		{
			writer.WritePropertyName("terms");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Rollup.TermsGroupingDescriptor<TDocument>(TermsDescriptorAction), options);
		}
		else if (TermsValue is not null)
		{
			writer.WritePropertyName("terms");
			JsonSerializer.Serialize(writer, TermsValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class GroupingsDescriptor : SerializableDescriptor<GroupingsDescriptor>
{
	internal GroupingsDescriptor(Action<GroupingsDescriptor> configure) => configure.Invoke(this);

	public GroupingsDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Rollup.DateHistogramGrouping? DateHistogramValue { get; set; }
	private Elastic.Clients.Elasticsearch.Rollup.DateHistogramGroupingDescriptor DateHistogramDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Rollup.DateHistogramGroupingDescriptor> DateHistogramDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Rollup.HistogramGrouping? HistogramValue { get; set; }
	private Elastic.Clients.Elasticsearch.Rollup.HistogramGroupingDescriptor HistogramDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Rollup.HistogramGroupingDescriptor> HistogramDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Rollup.TermsGrouping? TermsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Rollup.TermsGroupingDescriptor TermsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Rollup.TermsGroupingDescriptor> TermsDescriptorAction { get; set; }

	/// <summary>
	/// <para>
	/// A date histogram group aggregates a date field into time-based buckets.
	/// This group is mandatory; you currently cannot roll up documents without a timestamp and a <c>date_histogram</c> group.
	/// </para>
	/// </summary>
	public GroupingsDescriptor DateHistogram(Elastic.Clients.Elasticsearch.Rollup.DateHistogramGrouping? dateHistogram)
	{
		DateHistogramDescriptor = null;
		DateHistogramDescriptorAction = null;
		DateHistogramValue = dateHistogram;
		return Self;
	}

	public GroupingsDescriptor DateHistogram(Elastic.Clients.Elasticsearch.Rollup.DateHistogramGroupingDescriptor descriptor)
	{
		DateHistogramValue = null;
		DateHistogramDescriptorAction = null;
		DateHistogramDescriptor = descriptor;
		return Self;
	}

	public GroupingsDescriptor DateHistogram(Action<Elastic.Clients.Elasticsearch.Rollup.DateHistogramGroupingDescriptor> configure)
	{
		DateHistogramValue = null;
		DateHistogramDescriptor = null;
		DateHistogramDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The histogram group aggregates one or more numeric fields into numeric histogram intervals.
	/// </para>
	/// </summary>
	public GroupingsDescriptor Histogram(Elastic.Clients.Elasticsearch.Rollup.HistogramGrouping? histogram)
	{
		HistogramDescriptor = null;
		HistogramDescriptorAction = null;
		HistogramValue = histogram;
		return Self;
	}

	public GroupingsDescriptor Histogram(Elastic.Clients.Elasticsearch.Rollup.HistogramGroupingDescriptor descriptor)
	{
		HistogramValue = null;
		HistogramDescriptorAction = null;
		HistogramDescriptor = descriptor;
		return Self;
	}

	public GroupingsDescriptor Histogram(Action<Elastic.Clients.Elasticsearch.Rollup.HistogramGroupingDescriptor> configure)
	{
		HistogramValue = null;
		HistogramDescriptor = null;
		HistogramDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The terms group can be used on keyword or numeric fields to allow bucketing via the terms aggregation at a later point.
	/// The indexer enumerates and stores all values of a field for each time-period.
	/// This can be potentially costly for high-cardinality groups such as IP addresses, especially if the time-bucket is particularly sparse.
	/// </para>
	/// </summary>
	public GroupingsDescriptor Terms(Elastic.Clients.Elasticsearch.Rollup.TermsGrouping? terms)
	{
		TermsDescriptor = null;
		TermsDescriptorAction = null;
		TermsValue = terms;
		return Self;
	}

	public GroupingsDescriptor Terms(Elastic.Clients.Elasticsearch.Rollup.TermsGroupingDescriptor descriptor)
	{
		TermsValue = null;
		TermsDescriptorAction = null;
		TermsDescriptor = descriptor;
		return Self;
	}

	public GroupingsDescriptor Terms(Action<Elastic.Clients.Elasticsearch.Rollup.TermsGroupingDescriptor> configure)
	{
		TermsValue = null;
		TermsDescriptor = null;
		TermsDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (DateHistogramDescriptor is not null)
		{
			writer.WritePropertyName("date_histogram");
			JsonSerializer.Serialize(writer, DateHistogramDescriptor, options);
		}
		else if (DateHistogramDescriptorAction is not null)
		{
			writer.WritePropertyName("date_histogram");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Rollup.DateHistogramGroupingDescriptor(DateHistogramDescriptorAction), options);
		}
		else if (DateHistogramValue is not null)
		{
			writer.WritePropertyName("date_histogram");
			JsonSerializer.Serialize(writer, DateHistogramValue, options);
		}

		if (HistogramDescriptor is not null)
		{
			writer.WritePropertyName("histogram");
			JsonSerializer.Serialize(writer, HistogramDescriptor, options);
		}
		else if (HistogramDescriptorAction is not null)
		{
			writer.WritePropertyName("histogram");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Rollup.HistogramGroupingDescriptor(HistogramDescriptorAction), options);
		}
		else if (HistogramValue is not null)
		{
			writer.WritePropertyName("histogram");
			JsonSerializer.Serialize(writer, HistogramValue, options);
		}

		if (TermsDescriptor is not null)
		{
			writer.WritePropertyName("terms");
			JsonSerializer.Serialize(writer, TermsDescriptor, options);
		}
		else if (TermsDescriptorAction is not null)
		{
			writer.WritePropertyName("terms");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Rollup.TermsGroupingDescriptor(TermsDescriptorAction), options);
		}
		else if (TermsValue is not null)
		{
			writer.WritePropertyName("terms");
			JsonSerializer.Serialize(writer, TermsValue, options);
		}

		writer.WriteEndObject();
	}
}